package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysRoleDept;
import com.microcdyUser.service.SysRoleDeptService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysRoleDept")
@CrossOrigin
public class SysRoleDeptController {

    @Autowired
    private SysRoleDeptService sysRoleDeptService;

    /***
     * SysRoleDept分页条件搜索实现
     * @param sysRoleDept
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysRoleDept sysRoleDept, @PathVariable  int page, @PathVariable  int size){
        //调用SysRoleDeptService实现分页条件查询SysRoleDept
        PageInfo<SysRoleDept> pageInfo = sysRoleDeptService.findPage(sysRoleDept, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysRoleDept分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysRoleDeptService实现分页查询SysRoleDept
        PageInfo<SysRoleDept> pageInfo = sysRoleDeptService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysRoleDept
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysRoleDept>> findList(@RequestBody(required = false)  SysRoleDept sysRoleDept){
        //调用SysRoleDeptService实现条件查询SysRoleDept
        List<SysRoleDept> list = sysRoleDeptService.findList(sysRoleDept);
        return new Result<List<SysRoleDept>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用SysRoleDeptService实现根据主键删除
        sysRoleDeptService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysRoleDept数据
     * @param sysRoleDept
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysRoleDept sysRoleDept,@PathVariable Long id){
        //设置主键值
        sysRoleDept.setRoleId(id);
        //调用SysRoleDeptService实现修改SysRoleDept
        sysRoleDeptService.update(sysRoleDept);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysRoleDept数据
     * @param sysRoleDept
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysRoleDept sysRoleDept){
        //调用SysRoleDeptService实现添加SysRoleDept
        sysRoleDeptService.add(sysRoleDept);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysRoleDept数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysRoleDept> findById(@PathVariable Long id){
        //调用SysRoleDeptService实现根据主键查询SysRoleDept
        SysRoleDept sysRoleDept = sysRoleDeptService.findById(id);
        return new Result<SysRoleDept>(true,StatusCode.OK,"查询成功",sysRoleDept);
    }

    /***
     * 查询SysRoleDept全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysRoleDept>> findAll(){
        //调用SysRoleDeptService实现查询所有SysRoleDept
        List<SysRoleDept> list = sysRoleDeptService.findAll();
        return new Result<List<SysRoleDept>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
